from microbit import *

num =100
filename = 'data.cvs'

tm = [0]*num
dat = [0]*num

display.show(Image.TRIANGLE_LEFT)
while True:
    
    if button_a.is_pressed():
        display.show(Image.HEART)
        t = running_time()
        for i in range(100):
            tm[i] = running_time() - t
            dat[i] = accelerometer.get_y()
            sleep(1)
        f = open(filename, 'wt')
        f.write('Time, Acceleration\r\n')
        for i in range(100):
            f.write('{}, {}\r\n'.format(tm[i], dat[i]))
        f.close()
        display.show(Image.HEART_SMALL)
        sleep(500)
        display.show(Image.TRIANGLE_LEFT)

    if button_b.is_pressed():
        display.show(Image.HEART)
        f = open(filename)
        uart.write(f.read())
        sleep(500)
        f.close()
        display.show(Image.HEART_SMALL)
        display.show(Image.TRIANGLE_LEFT)
